package org.binarylook.nio;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.io.*;

public class Client implements Conf,Runnable {

    Socket s ;  
    
    public Client() {

    }
    
    public void dispatchClient() throws InterruptedException {

        try {
            s = new Socket(Conf.Server, Conf.Port);

            Thread t = new Thread(this,"mythread");
            t.start();

            System.out.println("Message has been sent");
            BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
            String str = br.readLine();
            System.out.println("receive message" + str);
            Thread.sleep(8455979);

        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void run(){

        try{
            PrintWriter pw  = new PrintWriter(s.getOutputStream(), true);
            pw.println("welcome to the concurrent world");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String msg ;
            while(true){
                msg = br.readLine();
            }
        }
        catch(IOException e){
            e.printStackTrace();
        }


    }

    public void SendMessage(){
        
    }
    public static void main(String arg[]) throws InterruptedException {
        Client bean = new Client();
        bean.dispatchClient();
    }


    
}
